package me.fung.wubi.base.define.action

import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import me.fung.wubi.base.define.value.Code
import me.fung.wubi.base.define.value.Word
import kotlin.coroutines.EmptyCoroutineContext

typealias ProcessAction = (Code, Word) -> Unit

fun ProcessAction?.runInBackground(code: Code, word: Word, dispatcher: CoroutineDispatcher = Dispatchers.IO) {
    if (this == null) return
    CoroutineScope(EmptyCoroutineContext).launch(dispatcher) {
        invoke(code, word)
    }
}